<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.UserDAO"%>
<%@page import="db.User"%>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	UserDAO userDao = (UserDAO)ctx.getBean("UserDAO");

	String oldPwd = request.getParameter("oldPwd");
	String newPwd = request.getParameter("newPwd");
	
	Integer userId = (Integer)session.getAttribute("id");
	User user = userDao.findById(userId);
	
	request.setAttribute("user",user);
	
	if(user.getPassword().equals(oldPwd)){
		if(newPwd.trim().length() > 5){
			user.setPassword(newPwd);
			userDao.attachDirty(user);
			request.setAttribute("info",3);
		}else{
			request.setAttribute("info",2);
		}
	}else{
		request.setAttribute("info",1);
	}
	
	pageContext.forward("/vm/erp_tpl/modPsw.vm");
%>